export default function ({ isHMR, app, store, route, params, error, redirect }) {
  
    let locale;  
    let default_lang=app.context.req.headers.cookie||'zh-CN';
    console.log(default_lang)
    if (default_lang === 'lang=zh-CN' || default_lang === 'lang=zh-cn'||default_lang === 'zh-CN'||default_lang === 'zh-cn') {
      locale = 'zh'
    } else {
      locale = 'en'
    }
   
    if (store.state.locales.indexOf(locale) === -1) {
      return error({ message: 'This page could not be found.', statusCode: 404 })
    }
    store.commit('SET_LANG', locale)
    app.i18n.locale = store.state.locale;
    if (locale === locale && route.fullPath.indexOf('/' + locale) === 0) {
      const toReplace = '^/' + locale + (route.fullPath.indexOf('/' + locale + '/') === 0 ? '/' : '')
      const re = new RegExp(toReplace)
      return redirect(
        route.fullPath.replace(re, '/')
      )
    }
  }
  